package utils;

/**
 * @author Created by 谭健 on 2018/4/16 0016. 星期一. 16:49.
 * © All Rights Reserved.
 * <p>
 * <p>
 * 浏览器工具类
 */
public class BrowserUtils {
    /**
     *
     * @param requestUserAgent = request.getHeader("USER-AGENT")
     * @return Browser 类型枚举
     */
    public static String getBrowser(String requestUserAgent) {
        if (distinguishAgent(requestUserAgent, IE)) { return "IE浏览器"; }
        if (distinguishAgent(requestUserAgent, QQ)) { return "QQ浏览器"; }
        if (distinguishAgent(requestUserAgent, SE360)) { return "360安全浏览器"; }
        if (distinguishAgent(requestUserAgent, FIRE_FOX)) { return "火狐浏览器"; }
        if (distinguishAgent(requestUserAgent, CHROME)) { return "谷歌浏览器"; }
        return "其它浏览器";
    }


    private static boolean distinguishAgent(String requestUserAgent, String agent) {
        if (requestUserAgent.indexOf(agent)>0){
            return true;
        }else {
            return false;
        }
    }


    private final static String
            IE = "MSIE",
            QQ = "QQBrowser",
            SE360 = "360SE",
            FIRE_FOX = "Firefox",
            CHROME = "Chrome";


    /*private enum Browser {

        IE6(""),
        IE7(""),
        IE8(""),
        IE9(""),
        IE10(""),
        IE11(""),
        FIRE_FOX("火狐浏览器"),
        MAX_THON("遨游浏览器"),
        QQ("QQ浏览器"),
        GREEN("GreenBrowser浏览器"),
        SE360("360安全浏览器"),
        OTHER("其它浏览器"),
        SAFARI("苹果Safari浏览器"),
        CHROME("谷歌浏览器"),
        OPERA("Opera浏览器"),
        CAMINO("MAC OS X下Camino浏览器"),
        GECKO("基于Gecko引擎开发的浏览器");

        private String describe;

        Browser(String describe) {
            this.describe = describe;
        }
    }*/
}
